$(function(){
    getComentarios();
});

function saveComment(form){
        $.ajax({
            type: "POST",
            url: url_saveComentario,
            data: form.serialize(),
            success: function(data) {
                $('#comments').append(data).hide().slideDown('slow');
            },
            beforeSend: function() {
                $('.btn').prop('disabled', true);
                $('.btn').val('enviando...');
                $('textarea').prop('disabled', true);
            },
            complete: function(){
                $('.btn').prop('disabled', false);
                $('.btn').val('Comentar');
                $('textarea').prop('disabled', false);
                $('textarea').val('');
            }
        });
}

function getComentarios(){
    $.ajax({
        type: "POST",
        url: url_getComentarios,
        success: function(data) {
            $('#comments_box').html(data);
        },
        complete: function(){
            $('#comments_loader').css('display', 'none');
            $('#comments_box').css('display', 'block');
        }
    });
}

function saveVoto(valor){
    $.ajax({
        type: "POST",
        url: url_saveVoto,
        data: {
            valor : valor
        },
        success: function(data){
            $('#rating').html(data);  
        },
        beforeSend: function() {
            $('#rating').css('display', 'none')
            $('#rating_loader').css('display', 'block');
        },
        complete: function(){
            $('#rating_loader').css('display', 'none');
            $('#rating').css('display', 'block');
        }
    });
}

